package com.example.demo.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
* @description: TODO
* @author 杨镇宇
* @date 2022/3/9 17:28
* @version 1.0
*/

public class CasTest {
    //它的底层是给予CAS操作的计数器
    static AtomicInteger num = new AtomicInteger(0);

    public static void main(String[] args) {
        for (int i=0;i<3;i++){
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    while (num.get()<1000){
                        System.out.println("thread name:"+Thread.currentThread().getName()+":"+num.incrementAndGet());
                    }
                }
            });
            thread.start();
        }
    }
}
